package com.grad.webstudy.service.impl;

import com.grad.webstudy.dao.RoleUserDao;
import com.grad.webstudy.model.RoleUser;
import com.grad.webstudy.service.RoleUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Description:
 * @Author: zjf
 * @Date: 2020/1/20 15:11.
 */
@Service
@Transactional
public class RoleUserServiceImpl implements RoleUserService {

    @Autowired
    private RoleUserDao roleUserDao;

    @Override
    public List<Integer> queryRoleIdsByUserId(int userId) {
        return roleUserDao.queryRoleIdsByUserId(userId);
    }

    @Override
    public boolean addUserRole(RoleUser roleUser) {

        return roleUserDao.addRoleUser(roleUser) > 0;
    }

    @Override
    public boolean addUserRoles(List<RoleUser> addRoleUsers) {

        return roleUserDao.addRoleUsers(addRoleUsers) == addRoleUsers.size();
    }

    @Override
    public boolean deleteRoleUsers(List<RoleUser> delRoleUsers) {
        return roleUserDao.deleteRoleUser(delRoleUsers) == delRoleUsers.size();
    }

    @Override
    public List<String> queryUserRoleName(Integer userId) {
        return roleUserDao.selectRoleUserName(userId);
    }

    @Override
    public boolean deleteRoleUsersByRoleIds(List<String> roleIds) {
        return roleUserDao.deleteRoleUsersByRoleIds(roleIds) > 0;
    }
}
